package com.rs.controller;

import java.awt.EventQueue;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;

import com.rs.model.ZhLeanprogress;
import com.rs.service.ZhLeanprogressService;
import com.rs.util.SpringContextUtils;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ZhLeanprogressListUpdate extends JFrame {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;

	private ZhLeanprogressService zhLeanprogressService = SpringContextUtils.getBean(ZhLeanprogressService.class);
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ZhLeanprogressListUpdate frame = new ZhLeanprogressListUpdate(null,null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ZhLeanprogressListUpdate( ZhLeanprogress zhLeanprogress,final JDesktopPane desktopPane_1) {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				ZhLeanprogressList zhLeanprogressList = new ZhLeanprogressList(desktopPane_1);
				zhLeanprogressList.setVisible(true);
				desktopPane_1.add(zhLeanprogressList);
			}
		});
		setBounds(100, 100, 690, 452);
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("大纲主题：");
		lblNewLabel.setBounds(82, 94, 60, 15);
		getContentPane().add(lblNewLabel);
		
		textField = new JTextField();
		textField.setText(zhLeanprogress.getLpgTheme());
		textField.setBounds(168, 91, 129, 21);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("大纲标题：");
		lblNewLabel_1.setBounds(82, 148, 60, 15);
		getContentPane().add(lblNewLabel_1);
		
		textField_1 = new JTextField();
		textField_1.setText(zhLeanprogress.getLpgTitle());
		textField_1.setBounds(168, 145, 129, 21);
		getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JLabel label = new JLabel("编号：");
		label.setBounds(82, 36, 54, 15);
		getContentPane().add(label);
		
		textField_2 = new JTextField();
		textField_2.setText(String.valueOf(zhLeanprogress.getLpgId()));
		textField_2.setEditable(false);
		textField_2.setBounds(168, 33, 66, 21);
		getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JLabel lblNewLabel_2 = new JLabel("大纲内容：");
		lblNewLabel_2.setBounds(357, 36, 60, 15);
		getContentPane().add(lblNewLabel_2);
		
		final JTextPane textPane = new JTextPane();
		textPane.setText(zhLeanprogress.getLpgTxt());
		textPane.setBounds(427, 36, 196, 191);
		getContentPane().add(textPane);
		
		JLabel lblNewLabel_3 = new JLabel("进度：");
		lblNewLabel_3.setBounds(82, 212, 54, 15);
		getContentPane().add(lblNewLabel_3);
		
		textField_3 = new JTextField();
		textField_3.setText(String.valueOf(zhLeanprogress.getLpgJd()));
		textField_3.setBounds(168, 206, 66, 21);
		getContentPane().add(textField_3);
		textField_3.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("课程类别：");
		lblNewLabel_4.setBounds(82, 277, 60, 15);
		getContentPane().add(lblNewLabel_4);
		
		final JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"java", "php"}));
		comboBox.setBounds(168, 274, 60, 21);
		getContentPane().add(comboBox);
		
		final JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"初级", "中级", "高级"}));
		comboBox_1.setBounds(168, 349, 60, 21);
		getContentPane().add(comboBox_1);
		
		JLabel lblNewLabel_5 = new JLabel("课程等级：");
		lblNewLabel_5.setBounds(82, 352, 60, 15);
		getContentPane().add(lblNewLabel_5);
		
		JButton btnNewButton = new JButton("修改");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZhLeanprogress zhLeanprogress = new ZhLeanprogress();
				zhLeanprogress.setLpgId(Integer.parseInt(textField_2.getText()));
				zhLeanprogress.setLpgTheme(textField.getText());
				zhLeanprogress.setLpgTitle(textField_1.getText());
				zhLeanprogress.setLpgTxt(textPane.getText());
				zhLeanprogress.setLpgJd(Integer.parseInt(textField_3.getText()));
				if (comboBox.getSelectedItem().equals("java")) {
					zhLeanprogress.setLpgType(0);
				}else {
					zhLeanprogress.setLpgType(1);
				}
				if (comboBox_1.getSelectedItem().equals("初级")) {
					zhLeanprogress.setLpgLeve(0);
				}else if(comboBox_1.getSelectedItem().equals("中级")){
					zhLeanprogress.setLpgLeve(1);
				}else {
					zhLeanprogress.setLpgLeve(2);
				}
				zhLeanprogressService.UpdateZhLean(zhLeanprogress);
				showMessageDialog("修改成功");
			}
		});
		btnNewButton.setBounds(530, 348, 93, 23);
		getContentPane().add(btnNewButton);

	}
	
	//提示弹窗
			public void showMessageDialog(String massage){
				JOptionPane.showMessageDialog(this,massage);
			}
}
